#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int n, m;
typedef struct
{
	int w;
	string name;
}S;
S s[N];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> s[i].w >> s[i].name;
	}
	int mark = 1;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		if (a + s[mark].w == 1) {
			mark = (mark + b) % n;
			if (!mark) {
				mark = n;
			}
		}
		else {
			mark = (mark - b + n) % n;
			if (!mark) {
				mark = n;
			}
		}
	}
	cout << s[mark].name << endl;
	return 0;
}